//
//  NewPaiHangViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/14.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewPaiHangViewController.h"
#import "NewTongJiTableViewCell.h"
#import "JTCSM.h"
#import "MyDoubleLabelView.h"
static CGFloat bottomblabelHeight = 44;
@interface NewPaiHangViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UIImageView *headerImageView;
}
@property (nonatomic,strong) NSMutableArray *titlearray;
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) UIImageView *userLogoImageV;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) MyDoubleLabelView *headerDoubleView;
@property (nonatomic,strong) MyDoubleLabelView *bottomDoubleView;
@end

@implementation NewPaiHangViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setHeaderView];
    UIImage * firstImage = [UIImage imageNamed:@"fanhui.png"];
    CGRect firstFrame = CGRectMake(20, 20, 50, 44);
    CGFloat width = firstFrame.size.width;
    CGFloat height = firstFrame.size.height;
    CGFloat imagesize = 20;
    UIButton * leftButton = [[UIButton alloc]initWithFrame:firstFrame];
    [leftButton setImage:firstImage forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(gotBack) forControlEvents:UIControlEventTouchUpInside];
    leftButton.imageEdgeInsets = UIEdgeInsetsMake((height-imagesize)/2, 0, (height-imagesize)/2, (width-imagesize));
    [self.view addSubview:leftButton];
    [self layoutTableView];
    // Do any additional setup after loading the view.
}
- (void)setHeaderView{
    
    UIImageView *backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 230)];
    backView.image = [UIImage imageNamed:@"排行榜背景.png"];
    [self.view addSubview:backView];
    backView.userInteractionEnabled = YES;
    CGFloat labelHeight = 20;
    CGFloat fontsize = (KSCREENWidth ==320?23:(KSCREENWidth==375?25:28));
    _headerDoubleView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(0, 64, KCONTROLLERWith, (backView.LC_height-64)/2-labelHeight-34) titleFontsize:14 titlecolor:[df colorWithHexString:@"fff94b" alpha:1] contentFontsize:fontsize contentcolor:[UIColor whiteColor]];
    [backView addSubview:_headerDoubleView];
    [_headerDoubleView InsertSpacesetvalueWithModel:@{KDoubleLabelTitle:@"今日收益排名",KDoubleLabelContent:@"89459845"} changeLabelY:5];
    
    self.titleLabel = [UILabel initWithFrame:CGRectMake(0, KVIEW_Y(_headerDoubleView)+14, KCONTROLLERWith, labelHeight) text:@"收益前1000名可获得红包奖励" font:14 textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"ffffff" alpha:.8] backgroundColor:nil];
    [backView addSubview:self.titleLabel];
    
    _bottomDoubleView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(self.titleLabel)+34, KCONTROLLERWith, _headerDoubleView.LC_height) titleFontsize:14 titlecolor:[df colorWithHexString:@"fff94b" alpha:1] contentFontsize:fontsize contentcolor:[UIColor whiteColor]];
    [backView addSubview:_bottomDoubleView];
    [_bottomDoubleView InsertSpacesetvalueWithModel:@{KDoubleLabelTitle:@"今日奖池金额",KDoubleLabelContent:@"¥89459845"} changeLabelY:8];
    
    
    CGFloat titleImagesize = 30;
    
    UIImageView *titleImageV= [[UIImageView alloc]initWithFrame:CGRectMake(20, backView.LC_height+(bottomblabelHeight-titleImagesize)/2, titleImagesize, titleImagesize)];
    titleImageV.image = [UIImage imageNamed:@"奖杯.png"];
    [self.view addSubview:titleImageV];
    
    UILabel *theLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(titleImageV)+10, backView.LC_height, KCONTROLLERWith, bottomblabelHeight) text:@"今日收益排行榜" font:12 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"666666" alpha:1] backgroundColor:nil];
    [self.view addSubview:theLabel];
   
}

- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, KCONTROLLERWith*0.5778+bottomblabelHeight, KCONTROLLERWith, KCONTROLLERHeight-(KCONTROLLERWith*0.5778+bottomblabelHeight)) style:UITableViewStylePlain];
    _tableview.backgroundColor = [UIColor whiteColor];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self setUpTableView];
    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self theRequestWithKeyWord:mykeyword];
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self loadMoreDataRequestWithKeyWord:mykeyword];
        
    });
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
    NewTongJiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[NewTongJiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid tongJiCellType:indexPath.row>2?NumberCellType:ImageCellType CellSata:DoubleLabelCellType];
    }
    [cell setValueWithModel:indexPath];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
